﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
					xmlns:diagnostics="clr-namespace:System.Diagnostics;assembly=WindowsBase">

	<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
	
	<LinearGradientBrush x:Key="LightBrush" StartPoint="0,0" EndPoint="0,1">
		<GradientBrush.GradientStops>
			<GradientStopCollection>
				<GradientStop Color="#333" Offset="0.0"/>
				<GradientStop Color="#000" Offset="1.0"/>
			</GradientStopCollection>
		</GradientBrush.GradientStops>
	</LinearGradientBrush>

	<SolidColorBrush x:Key="SolidBorderBrush" Color="#444" />
	<SolidColorBrush x:Key="TabItemBackgroundBrush" Color="#444" />
	<SolidColorBrush x:Key="DisabledBackgroundBrush" Color="#111" />
	<SolidColorBrush x:Key="DisabledBorderBrush" Color="#555" />
	<SolidColorBrush x:Key="DisabledForegroundBrush" Color="DarkGray" />
	<SolidColorBrush x:Key="EnabledForegroundBrush" Color="LightGray" />

	<DataTemplate x:Key="TabHeaderDataTemplate">
		<StackPanel Orientation="Horizontal" VerticalAlignment="Stretch">
			<TextBlock x:Name="textBlock" 
					   Text="{Binding Title}" 
					   HorizontalAlignment="Left" TextTrimming="CharacterEllipsis" 
					   TextWrapping="NoWrap" Foreground="#FFFFFFFF" Margin="0,2,0,0"  
					   FontFamily="Arial" FontSize="11" />
			<TextBlock Text="*" 
					   Visibility="{Binding Path=Content.Dirty, FallbackValue=Collapsed, Converter={StaticResource BooleanToVisibilityConverter}}"
					   HorizontalAlignment="Left" Foreground="#FFFFFFFF" Margin="0,2,0,0" />
			<Button x:Name="button"  
					Command="ApplicationCommands.Close" CommandParameter="{Binding diagnostics:PresentationTraceSources.TraceLevel=None, Path=Content, RelativeSource={RelativeSource AncestorType={x:Type TabItem}, Mode=FindAncestor}}" 
					Template="{DynamicResource CloseTabButtonControlTemplate}" 
					Background="{x:Null}" BorderBrush="{x:Null}" Foreground="{x:Null}" 
					Width="9" Height="9" Opacity="1" ToolTip="Close" 
					Margin="8,3,0,0" VerticalAlignment="Stretch" BorderThickness="0"
					HorizontalAlignment="Right" />
		</StackPanel>
	</DataTemplate>

	<Style TargetType="{x:Type TabItem}">
		<Setter Property="Header" Value="{Binding ViewModel}" />
		<Setter Property="HeaderTemplate" Value="{DynamicResource TabHeaderDataTemplate}" />
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="{x:Type TabItem}">
					<Grid>
						<Border 
							Name="Border"
							Margin="0,0,-4,0" 
							Background="{StaticResource LightBrush}"
							BorderBrush="{StaticResource SolidBorderBrush}" 
							BorderThickness="1,1,1,1" 
							CornerRadius="2,12,0,0">
							<ContentPresenter x:Name="ContentSite"
							  VerticalAlignment="Center"
							  HorizontalAlignment="Center"
							  ContentSource="Header"
							  Margin="12,2,12,2"
							  RecognizesAccessKey="True" />
						</Border>
					</Grid>
					<ControlTemplate.Triggers>
						<Trigger Property="IsSelected" Value="True">
							<Setter Property="Panel.ZIndex" Value="100" />
							<Setter TargetName="Border" Property="Background" Value="{StaticResource TabItemBackgroundBrush}" />
							<Setter TargetName="Border" Property="BorderThickness" Value="1,1,1,0" />
						</Trigger>
						<Trigger Property="IsEnabled" Value="False">
							<Setter TargetName="Border" Property="Background" Value="{StaticResource DisabledBackgroundBrush}" />
							<Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource DisabledBorderBrush}" />
							<Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}" />
						</Trigger>
						<Trigger Property="IsEnabled" Value="true">
							<Setter Property="Foreground" Value="{StaticResource EnabledForegroundBrush}" />
						</Trigger>
					</ControlTemplate.Triggers>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>

</ResourceDictionary>